package com.luomu.base.control.cookBook.excel.controller;

import com.alibaba.fastjson.JSONObject;
import com.luomu.base.api.bo.RspBaseBO;
import com.luomu.base.api.bo.RspPage;
import com.luomu.base.api.cookBook.excel.bo.*;
import com.luomu.base.api.cookBook.excel.service.CommonExcelExportService;
import com.luomu.base.api.cookBook.simple.bo.FinanceArApAndInvoiceInfoReqBO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/apis/excel")
public class ExcelController {

    protected Logger log = LoggerFactory.getLogger(ExcelController.class);

    @Autowired
    private CommonExcelExportService commonExcelExportService;

    /**
     * 通用excel导出策略
     * @param @param req
     * @param @return    参数
     * @return RspBaseBO    返回类型
     */
    @RequestMapping(value = "/export", method = RequestMethod.POST)
    public RspBaseBO export(@RequestBody @Valid FinanceArApAndInvoiceInfoReqBO reqBO) {
        CommonExcelExportReq commonExcelExportReq = new CommonExcelExportReq();
        BeanUtils.copyProperties(reqBO, commonExcelExportReq);
        commonExcelExportReq.setOriginType(2);
        commonExcelExportReq.setRequestParam(JSONObject.toJSONString(reqBO));
        return commonExcelExportService.export(commonExcelExportReq);
    }

    /**
     * 通用查询导出结果数据
     * @param @param req
     * @param @return    参数
     * @return RspPage<CommonExportListDataRspBO>    返回类型
     */
    @RequestMapping(value = "/queryData", method = RequestMethod.POST)
    public RspPage<CommonExportListDataRspBO> queryData(@RequestBody @Valid CommonExportListDataReqBO reqBO) {
        reqBO.setOriginType(2);
        return commonExcelExportService.queryCommonExcelExport(reqBO);
    }

    /**
     * 删除导出数据
     * @param @param req
     * @param @return    参数
     * @return RspBaseBO    返回类型
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public RspBaseBO delete(@RequestBody @Valid CommonExcelExportOperationReq reqBO) {
        return commonExcelExportService.delete(reqBO);
    }

    /**
     * 下载导出地址
     * @param @param req
     * @param @return    参数
     * @return String    返回类型
     */
    @RequestMapping(value = "/download", method = RequestMethod.POST)
    public RspBaseBO download(@RequestBody @Valid CommonExcelExportOperationReq reqBO) {
        return commonExcelExportService.download(reqBO);
    }


}
